/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.gui.tbl;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.apache.log4j.Logger;
import org.tnmk.worktime.utils.NumUtils;

/**
 *
 * @author Administrator
 */
public class NumberCellRenderer extends DecorateDefaultTableCellRenderer {
  private final Logger log = Logger.getLogger(NumberCellRenderer.class);

  public NumberCellRenderer() {
    super();
  }

  public NumberCellRenderer(DefaultTableCellRenderer previousRenderer) {
    super(previousRenderer);
  }

  @Override
  public Component getTableCellRendererComponent(JLabel comp, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (value == null) return comp;
    try {
      Float data = NumUtils.toFloat(value);
      String str = NumUtils.toString(data);
      comp.setText(str);
    } catch (Exception ex) {
      log.error("Cannot format value: "+ value, ex);
    }
    return comp;
  }
}
